FILE(GLOB_RECURSE SOURCES ${PROJECT_SOURCE_DIR}/protocol/*.cpp)
FILE(GLOB COMMON_PROTO ${PROJECT_SOURCE_DIR}/protocol/Proto/*.proto)

SET(PROTO_PATH "${PROJECT_SOURCE_DIR}/protocol/Proto/")
SET(CPP_PATH "${PROJECT_SOURCE_DIR}/protocol/Proto/Imp")

FOREACH(PROTO_FILE ${COMMON_PROTO})
    #去除proto扩展名
    STRING(REGEX REPLACE ".proto$" "" PROTO_FILE_WE ${PROTO_FILE})

    LIST(APPEND SOURCES "${PROTO_FILE_WE}.pb.cc")
    ADD_CUSTOM_COMMAND(
        OUTPUT "${PROTO_FILE_WE}.pb.h" "${PROTO_FILE_WE}.pb.cc"
        COMMAND  ${PROTOBUFF_BIN}
        ARGS --cpp_out ${PROJECT_SOURCE_DIR}
        --python_out=${PROJECT_SOURCE_DIR}
        --proto_path=${PROJECT_SOURCE_DIR} ${PROTO_FILE}
        DEPENDS ${PROTO_FILE}
        )
ENDFOREACH(PROTO_FILE)

INCLUDE_DIRECTORIES(
    ${PROJECT_SOURCE_DIR}
    ${PROTOBUFF_INCLUDE}
    )

ADD_LIBRARY(protocol STATIC ${SOURCES})
#TARGET_LINK_LIBRARIES(protocol ${PROTOBUFF_LIB})

SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/protocol)
